// @charset "utf-8";
/**
 * 个股涨跌画图
 */
define(function(require, exports, module) {

	var ggzdChart = {
		$chartDom : $('#view_div_ggzdchart'),
		ggzdHighcharts: null,
		changeSize: function () {
			var windowWidth = $(window).width(),
				windowHeight = $(window).height();
			$('.container').height(windowHeight).width(windowWidth);
			$('.tab-content-item').height(windowHeight - 26);
			$('.chart-content, .chart-c').height(windowHeight - 26 - 15)
				.width(windowWidth - 4);

			// $('#view_div_dqfxchart').height(windowHeight - 26 - 5);

			$('.reading-content').height(windowHeight - 30)
				.width(windowWidth - 4);

			var readChartWidth = (windowWidth - 22) * 0.4;
			$('#view_div_readchart').height(readChartWidth * 0.7)
				.width(readChartWidth);

			// xgsg
			$('.xgsg-content').height(windowHeight - 26).width(windowWidth - 10);
			$('.data-box').height(windowHeight - 26 - 28 - 17);
		},
		render : function(zdtjDataTotal, zdtjRiseData, zdtjFalldata, result) {
			var self = this;
			var maxGgzdData = 200;
			if (zdtjDataTotal != 0) {
				maxGgzdData = Math.max.apply(null, result) + 200;
			}
			result.push(null);
			var ggzdChartConfig = {
				credits: {
					enabled: false
				},
				title: {
					text: ''
				},
				chart: {
					backgroundColor: "rgba(0,0,0,0)",
					style: {
						fontFamily: "arial"
					},
					marginLeft: 40,
					marginTop: 36
				},
				series: [{
					name: '涨跌停',
					type: 'column',
					marker: {
						enabled: false
					},
					data: result
				}],
				plotOptions: {
					column: {
						borderWidth: 0,
						pointPlacement: 'between',
						colorByPoint: true,
						colors: ['red', 'red', 'red', 'red', 'red', 'red', 'red', 'red', 'red', 'red', 'green', 'green', 'green', 'green', 'green', 'green', 'green', 'green', 'green', 'green', 'green']
					},
					series: {
						dataLabels: {
							color: '#808080',
							style: {
								fontWeight: 'normal',
								textShadow: 'null'
							},
							backgroundColor: null,
							shadow: false,
							enabled: true,
							y: 4
						},
						events: {
							legendItemClick: function() {
								return false;
							}
						}
					}
				},
				labels: {
					style: {
						fontFamily: "simsun",
						fontSize: 12
					}
				},
				xAxis: {
					tickmarkPlacement: 'on',
					lineWidth: 1,
					tickLength: 4,
					lineColor: '#808080',
					tickColor: '#808080',
					useHtml: true,
					tickInterval: 1,
					title: {
						text: ''
					},
					categories: ['涨停', '9', '8', '7', '6', '5', '4', '3', '2', '1', '0', '-1', '-2', '-3', '-4', '-5', '-6', '-7', '-8', '-9', '跌停'],
					gridLineWidth: 0,
					labels: {
						align: 'center',
						rotation: '0',
						style: {
							color: '#afafaf',
							fontFamily: "simsun",
							fontSize: 12
						},
						useHTML: true,
						formatter: function() {
							if (this.value > 0 || this.value === '涨停') {
								return '<span style="color:red">' + this.value + '</span>';
							} else if (this.value === '0') {
								return this.value;
							} else {
								return '<span style="color:green">' + this.value + '</span>';
							}
						}
					}
				},
				yAxis: {
					lineWidth: 1,
					tickColor: '#808080',
					tickPosition: 'outside',
					gridLineWidth: 0,
					tickLength: 4,
					tickWidth: 1,
					title: {
						text: ''
					},
					lineColor: '#808080',
					labels: {
						format: '{value}',
						style: {
							color: '#afafaf'
						},
						x: -7
					},
					max : maxGgzdData

				},
				legend: {
					enabled: true,
					align: 'right',
					verticalAlign: 'top',
					floating: true,
					symbolHeight: 0,
					symbolWidth: 0,
					itemStyle: {
						color: '#dedede',
						fontFamily: 'simsun',
						fontWeight: 'normal'
					},
					itemHiddenStyle: {},
					itemHoverStyle: {
						color: '#dedede'
					},
					useHTML: true,
					labelFormatter: function() {
						return '<span class="zdtj-legend">上涨<i class="zdtj-legend-risedata">' + zdtjRiseData + '</i></span>' +
							'<span class="zdtj-legend zdtj-legend-fall">下跌<i class="zdtj-legend-falldata">' + zdtjFalldata + '</i></span>';
					},
					y : -8
				},
				tooltip: {
					formatter: function() {
						var ratio;
						if (zdtjDataTotal != 0) {
							ratio = parseFloat(this.y / zdtjDataTotal * 100).toFixed(2);
						} else {
							ratio = '--';
						}
						return '占当日交易股票的' + ratio + '%';
					}
				}
			};
			self.changeSize();
			this.$chartDom.highcharts(ggzdChartConfig);
			this.ggzdHighcharts = this.$chartDom.highcharts();
		},
		reflowChart: function () {
			if (this.ggzdHighcharts != null) {
				this.ggzdHighcharts.reflow();
			}
		}
	};

	module.exports = ggzdChart;
});